/**
 * @author chongw
 * @since 2021-06-01 14:24:29
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-form");

    // 自定义验证规则
    form.verify({
        sort: function(value){
            if (!/^[0-9]+$/.test(value)) {
                return "排序值只能是正整数";
            }
        },
        integer: [
            /^[1-9]\d*$/
            , '只能输入正整数'
        ]
    });

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        let index;
        let data = obj.field;
        $.ajax({
            async: false,
            type: "POST",
            url: "/brs/objective/rule/modifyRule.action",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(data),
            beforeSend: function () {
                index = layer.load(1, {
                    shade: [0.5, '#DBDBDB']
                });
            },
            success:function(data) {
                if (data.status === 200) {
                    layer.msg("配置规则修改成功！",{"icon": 1,"time":1000},function (){
                        parent.location.reload();
                    });
                } else {
                    layer.msg(data.message, {"icon": 2});
                }
                layer.close(index);
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        return false;
    });

    //对外暴露的接口
    exports('brs_objective_rule_detail', {});
});

// 取消
function cancel() {
    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}